const util = require('util');
const debug = util.debuglog('oil-game:welfare:action');

//增加石油
exports.addOil = function (session, changeNum) {
  let {uid, frontendId } = session;
  debug("uid = %s  frontendId = %s  changeNum = %s 增加石油", uid, frontendId, changeNum);
  return new Promise((resolve, reject) => {
    this.app.rpc.login.loginRemote.addOil(session, uid, frontendId, changeNum, "welfare",function (err, data) {
      if(err){
        debug("uid = %s  增加石油异常  %s", uid, JSON.stringify(err));
        return reject(err);
      }
      debug("uid = %s  增加石油成功，结果为 %s", uid, JSON.stringify(data));
      resolve(data);
    });
  });
}

//增加金币
exports.addCoins = function (session, coins) {
  let { uid } = session;
  debug("uid = %s  coins = %s 增加金币", uid, coins);
  return new Promise((resolve, reject) => {
    this.app.rpc.login.loginRemote.addCoins(session, uid, session.frontendId, coins, true, function (err, data) {
      if(err){
        debug("uid = %s  coins = %s 增加金币异常  %s", uid, coins, JSON.stringify(err));
        return reject(err);
      }
      debug("uid = %s  coins = %s 增加金币成功，结果为 %s", uid, coins, JSON.stringify(data));
      resolve(data);
    });
  });
}
